package com.mylove.judas.yaya.ui;

import android.app.Application;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.DisplayMetrics;

import com.mylove.judas.yaya.common.utils.DensityUtil;

/**
 * Created by Judas on 2017/7/25.
 */

public class App extends Application {


    //转场动画允许最小系统版本
    private static int minapiVersion = 20;

    //当前系统版本
    private static int currentapiVersion;

    //App实例
    private static App instance;

    private static long mainThreadTid;

    @Override
    public void onCreate() {
        super.onCreate();

        //初始化系统默认配置
        initConfig();

        //初始化App实例
        instance = this;

        //获取系统版本号
        currentapiVersion = android.os.Build.VERSION.SDK_INT;

        //获取屏幕宽高
        getScreenWH();
    }

    /**
     * 初始化系统默认配置
     */
    public void initConfig(){
        Resources res = super.getResources();
        Configuration config = new Configuration();
        config.setToDefaults();
        res.updateConfiguration(config, res.getDisplayMetrics());
    }

    /**
     * 是否启用转场动画
     * @return
     */
    public static boolean isEnableTransferAnim(){

        return currentapiVersion >= minapiVersion;
    }


    /**
     * 获取App实例
     * @return
     */
    public static App getInstance(){

        return instance;
    }


    /**
     * 获取线程Id
     * @return
     */
    public static long getMainThreadTid(){
        return mainThreadTid;
    }


    /**
     * 获取屏幕宽高
     */
    private void getScreenWH() {
        DisplayMetrics dm = getResources().getDisplayMetrics();
        if(dm.widthPixels < dm.heightPixels) {
            DensityUtil.screenWidth = dm.widthPixels;
            DensityUtil.screenHeight = dm.heightPixels;
        } else {
            DensityUtil.screenHeight = dm.widthPixels;
            DensityUtil.screenWidth = dm.heightPixels;
        }
    }


    //用户退出操作
    public static final String ACTION_LOGIN_OUT = "login_out";
    //发布成功
    public static final String ACTION_PUBLISH_SUCCESS = "publish_success";
    
}
